package com.zhang.service;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import javax.annotation.Resource;
import java.net.URL;

public class ArticleParse {

    //HttpClientService client = new HttpClientService();

    public String parseArticle(String href) {

        String url = "https://www.czu.cn" + href;
        System.out.println("222内容解析");
        //文章的内容
        String content;
        try {
            Document document = Jsoup.parse(new URL(url), 180000);

            //Document document = Jsoup.parse(client.getHtml(url));
            System.out.println("开始解析content");
            Element el = document.getElementsByClass("article").first(); //获取整个article块
            content = el.html();
            content = new DeleteStyle().removeContentStyle(content);
            return content;
        }catch (Exception e){
            return "";//文章格式难以识别，用链接代替div存储
        }
    }
}